package helpers

import (
	"crypto/md5"
	"fmt"
	"io"
)

func DefaultValue(value string, defaultValue interface{}) interface{} {
	if value == "" {
		return defaultValue
	}
	return value
}

// PasswordEncrypt 密码加密
func PasswordEncrypt(value string) string {
	h := md5.New()
	io.WriteString(h, value)
	pwdMd5 := fmt.Sprintf("%x", h.Sum(nil))
	io.WriteString(h, pwdMd5)
	return fmt.Sprintf("%x", h.Sum(nil))
}
